package top.kiterunner.learning.moon_test;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

/**
 * AdorynZhao in Tencent-UESTC.
 * Source Code Created on 2017/8/3.
 */
public class Utility {

    public static byte[] intToByteArray(int intval) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(4);
        IntBuffer intBuffer = byteBuffer.asIntBuffer();
        intBuffer.put(intval);

        return byteBuffer.array();
    }

    public static void main(String[] args) {
        byte[] bytes1 = intToByteArray(23);
        for (int i = 0; i < bytes1.length; i++) {
            System.out.format("%x", bytes1[i]);
        }

        System.out.println();

        byte[] bytes2 = ByteBuffer.allocate(4).putInt(23).array();
        for (int i = 0; i < bytes2.length; i++) {
            System.out.format("%x", bytes2[i]);
        }
    }
}
